- EnvIO ( CancellationToken Token, CancellationTokenSource Source, SynchronizationContext? SyncContext)
- New ( CancellationToken token, CancellationTokenSource source, SynchronizationContext? syncContext)
- New ()
- New (CancellationTokenSource src)
- LocalCancel
- LocalSyncContext
- Dispose ()
- ToString ()
- ForkIO <A> (IO<Unit> Cancel, IO<A> Await)
- IO <A> (Func<EnvIO, A> runIO)
- Pure (A value)
- Fail (Error value)
- Empty = new(_ => throw new ManyExceptions([]))
- Lift (Func<A> f)
- Lift (Func<EnvIO, A> f)
- LiftAsync (Func<ValueTask<A>> f)
- LiftAsync (Func<EnvIO, ValueTask<A>> f)
- Map <B> (Func<A, B> f)
- MapFail (Func<Error, Error> f)
- BiMap <B> (Func<A, B> Succ, Func<Error, Error> Fail)
- Match <B> (Func<A, B> Succ, Func<Error, B> Fail)
- IfFail (Func<Error, A> Fail)
- IfFail (A Fail)
- Fold <S> ( Schedule schedule, S initialState, Func<S, A, S> folder)
- Fold <S> ( S initialState, Func<S, A, S> folder)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<S, bool> stateIs)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<A, bool> valueIs)
- FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate)
- Post ()
- Bind <B> (Func<A, IO<B>> f)
- Bind <B> (Func<A, K<IO, B>> f)
- Bind <B> (Func<A, Pure<B>> f)
- Select <B> (Func<A, B> f)
- SelectMany <B, C> (Func<A, IO<B>> bind, Func<A, B, C> project)
- SelectMany <B, C> (Func<A, Pure<B>> bind, Func<A, B, C> project)
- SelectMany <M, B, C> (Func<A, OptionT<M, B>> bind, Func<A, B, C> project)
- SelectMany <M, B, C> (Func<A, TryT<M, B>> bind, Func<A, B, C> project)
- SelectMany <L, M, B, C> (Func<A, EitherT<L, M, B>> bind, Func<A, B, C> project)
- SelectMany <F, M, B, C> (Func<A, ValidationT<F, M, B>> bind, Func<A, B, C> project)
- SelectMany <Env, M, B, C> (Func<A, ReaderT<Env, M, B>> bind, Func<A, B, C> project)
- SelectMany <S, M, B, C> (Func<A, StateT<S, M, B>> bind, Func<A, B, C> project)
- SelectMany <M, B, C> (Func<A, ResourceT<M, B>> bind, Func<A, B, C> project)
- SelectMany <B, C> (Func<A, Eff<B>> bind, Func<A, B, C> project)
- SelectMany <RT, B, C> (Func<A, Eff<RT, B>> bind, Func<A, B, C> project)
- SelectMany <C> (Func<A, Guard<Error, Unit>> bind, Func<A, Unit, C> project)
- Or (IO<A> mb)
- | (IO<A> ma, IO<A> mb)
- | (IO<A> ma, Pure<A> mb)
- | (IO<A> ma, Fail<Error> mb)
- | (IO<A> ma, Fail<Exception> mb)
- | (IO<A> ma, Error mb)
- | (IO<A> ma, CatchError mb)
- | (IO<A> ma, CatchValue<A> mb)
- | (IO<A> ma, CatchIO<A> mb)
- | (IO<A> ma, CatchM<IO, A> mb)
- | (IO<A> ma, CatchError<Error> mb)
- | (IO<A> ma, CatchError<Exception> mb)
- | (IO<A> ma, CatchValue<Error, A> mb)
- | (IO<A> ma, CatchValue<Exception, A> mb)
- Timeout (TimeSpan timeout)
- Fork (Option<TimeSpan> timeout = default)
- Run ()
- Run (EnvIO env)
- Repeat ()
- Repeat (Schedule schedule)
- RepeatWhile (Func<A, bool> predicate)
- RepeatWhile ( Schedule schedule, Func<A, bool> predicate)
- RepeatUntil ( Func<A, bool> predicate)
- RepeatUntil ( Schedule schedule, Func<A, bool> predicate)
- Retry ()
- Retry (Schedule schedule)
- RetryWhile (Func<Error, bool> predicate)
- RetryWhile ( Schedule schedule, Func<Error, bool> predicate)
- RetryUntil ( Func<Error, bool> predicate)
- RetryUntil ( Schedule schedule, Func<Error, bool> predicate)
- ToString ()
- IOExtensions
- As <A> (this K<IO, A> ma)
- Flatten <A> (this Task<IO<A>> tma)
- Flatten <A> (this IO<IO<A>> mma)
- Await <A> (this K<IO, ForkIO<A>> ma)
- Fork <M, A> (this K<M, A> ma, Option<TimeSpan> timeout = default)
- Apply <A, B> (this IO<Func<A, B>> ff, IO<A> fa)
- Action <A, B> (this IO<A> fa, IO<B> fb)
- IO
- Fail <A> (Error value)
- lift (Action f)
- local <A> (K<IO, A> ma)
- lift <A> (Either<Error, A> ma)
- lift <A> (Fin<A> ma)
- lift <A> (Func<A> f)
- lift <A> (Func<EnvIO, A> f)
- lift <A> (Func<Fin<A>> f)
- lift <A> (Func<EnvIO, Fin<A>> f)
- lift <A> (Func<Either<Error, A>> f)
- lift <A> (Func<EnvIO, Either<Error, A>> f)
- liftAsync <A> (Func<ValueTask<A>> f)
- liftAsync <A> (Func<EnvIO, ValueTask<A>> f)
- env = lift(e => e)
- token = lift(e => e.Token)
- source = lift(e => e.Source)
- syncContext = lift(e => Optional(e.SyncContext))
- bind <A, B> (K<IO, A> ma, Func<A, K<IO, B>> f)
- map <A, B> (Func<A, B> f, K<IO, A> ma)
- map <A, B> (Func<A, B> f, IO<A> ma)
- apply <A, B> (K<IO, Func<A, B>> mf, K<IO, A> ma)
- action <A, B> (K<IO, A> ma, K<IO, B> mb)
- empty <A> ()
- or <A> (K<IO, A> ma, K<IO, A> mb)
- fork <A> (K<IO, A> ma, Option<TimeSpan> timeout = default)
- yield (double milliseconds)
- IO
- Prelude
- cancelToken = IO.lift(e => e.Token)
- cancel = new (e => { e.Source.Cancel(); throw new TaskCanceledException(); })
- unitIO = IO<Unit>.Pure(default)
- envIO = IO<EnvIO>.Lift(e => e)
- local <A> (K<IO, A> ma)
- fork <M, A> (K<M, A> ma, Option<TimeSpan> timeout = default)
- timeout <A> (TimeSpan timeout, K<IO, A> ma)
- repeat <A> (K<IO, A> ma)
- repeat <A> (Schedule schedule, K<IO, A> ma)
- repeatWhile <A> (K<IO, A> ma, Func<A, bool> predicate)
- repeatWhile <A> ( Schedule schedule, K<IO, A> ma, Func<A, bool> predicate)
- repeatUntil <A> ( K<IO, A> ma, Func<A, bool> predicate)
- repeatUntil <A> ( Schedule schedule, K<IO, A> ma, Func<A, bool> predicate)
- retry <A> (K<IO, A> ma)
- retry <A> (Schedule schedule, K<IO, A> ma)
- retryWhile <A> ( K<IO, A> ma, Func<Error, bool> predicate)
- retryWhile <A> ( Schedule schedule, K<IO, A> ma, Func<Error, bool> predicate)
- retryUntil <A> ( K<IO, A> ma, Func<Error, bool> predicate)
- retryUntil <A> ( Schedule schedule, K<IO, A> ma, Func<Error, bool> predicate)
- yield (double milliseconds)
record EnvIO ( CancellationToken Token, CancellationTokenSource Source, SynchronizationContext? SyncContext) Source #
Environment for the IO monad
property EnvIO LocalCancel Source #
property EnvIO LocalSyncContext Source #
record ForkIO <A> (IO<Unit> Cancel, IO<A> Await) Source #
Result of forking an IO
monad
type | A | Bound value type |
param | Cancel | An |
param | Await | An |
record IO <A> (Func<EnvIO, A> runIO) Source #
A value of type IO
a is a computation which, when performed, does some I/O before returning
a value of type A
.
There is really only one way you should "perform" an I/O action: bind it to Main
in your
program: When your program is run, the I/O will be performed. It shouldn't be possible to
perform I/O from an arbitrary function, unless that function is itself in the IO
monad and
called at some point, directly or indirectly, from Main
.
Obviously, as this is C#, the above restrictions are for you to enforce. It would be reasonable to relax that approach and have I/O invoked from, say, web-request handlers - or any other 'edges' of your application.
IO
is a monad, so IO
actions can be combined using either the LINQ-notation or the bind
operations from the Monad
class.
type | A | Bound value |
param | runIO | The lifted thunk that is the IO operation |
field IO<A> Empty = new(_ => throw new ManyExceptions([])) Source #
method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #
method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #
method IO<S> FoldWhile <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #
method IO<S> FoldWhile <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #
method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<S, bool> stateIs) Source #
method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<A, bool> valueIs) Source #
method IO<S> FoldUntil <S> ( S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #
method IO<S> FoldUntil <S> ( Schedule schedule, S initialState, Func<S, A, S> folder, Func<(S State, A Value), bool> predicate) Source #
Make this IO computation run on the SynchronizationContext
that was captured at the start
of the IO chain (i.e. the one embedded within the EnvIO
environment that is passed through
all IO computations)
method IO<C> SelectMany <B, C> (Func<A, IO<B>> bind, Func<A, B, C> project) Source #
method IO<C> SelectMany <B, C> (Func<A, Pure<B>> bind, Func<A, B, C> project) Source #
method OptionT<M, C> SelectMany <M, B, C> (Func<A, OptionT<M, B>> bind, Func<A, B, C> project) Source #
method TryT<M, C> SelectMany <M, B, C> (Func<A, TryT<M, B>> bind, Func<A, B, C> project) Source #
method EitherT<L, M, C> SelectMany <L, M, B, C> (Func<A, EitherT<L, M, B>> bind, Func<A, B, C> project) Source #
method ValidationT<F, M, C> SelectMany <F, M, B, C> (Func<A, ValidationT<F, M, B>> bind, Func<A, B, C> project) Source #
method ReaderT<Env, M, C> SelectMany <Env, M, B, C> (Func<A, ReaderT<Env, M, B>> bind, Func<A, B, C> project) Source #
method StateT<S, M, C> SelectMany <S, M, B, C> (Func<A, StateT<S, M, B>> bind, Func<A, B, C> project) Source #
method ResourceT<M, C> SelectMany <M, B, C> (Func<A, ResourceT<M, B>> bind, Func<A, B, C> project) Source #
method Eff<C> SelectMany <B, C> (Func<A, Eff<B>> bind, Func<A, B, C> project) Source #
method Eff<RT, C> SelectMany <RT, B, C> (Func<A, Eff<RT, B>> bind, Func<A, B, C> project) Source #
method IO<C> SelectMany <C> (Func<A, Guard<Error, Unit>> bind, Func<A, Unit, C> project) Source #
method IO<A> Timeout (TimeSpan timeout) Source #
Applies a time limit to the IO computation. If exceeded an exception is thrown.
param | timeout | Timeout |
returns | Result of the operation or throws if the time limit exceeded. |
method IO<ForkIO<A>> Fork (Option<TimeSpan> timeout = default) Source #
Queues the specified work to run on the thread pool
param | timeout | Optional timeout |
returns |
|
Run the IO
monad to get its result
Any lifted asynchronous operations will yield to the thread-scheduler, allowing other queued operations to run concurrently. So, even though this call isn't awaitable it still plays nicely and doesn't block the thread.
NOTE: An exception will always be thrown if the IO operation fails. Lift this monad into other error handling monads to leverage more declarative error handling.
returns | Result of the IO operation |
method A Run (EnvIO env) Source #
Run the IO
monad to get its result
Any lifted asynchronous operations will yield to the thread-scheduler, allowing other queued operations to run concurrently. So, even though this call isn't awaitable it still plays nicely and doesn't block the thread.
NOTE: An exception will always be thrown if the IO operation fails. Lift this monad into other error handling monads to leverage more declarative error handling.
param | env | IO environment |
returns | Result of the IO operation |
method IO<A> Repeat () Source #
Keeps repeating the computation forever, or until an error occurs
returns | The result of the last invocation |
method IO<A> Repeat (Schedule schedule) Source #
Keeps repeating the computation, until the scheduler expires, or an error occurs
param | schedule | Scheduler strategy for repeating |
returns | The result of the last invocation |
method IO<A> RepeatWhile (Func<A, bool> predicate) Source #
Keeps repeating the computation until the predicate returns false, or an error occurs
param | predicate | Keep repeating while this predicate returns |
returns | The result of the last invocation |
method IO<A> RepeatWhile ( Schedule schedule, Func<A, bool> predicate) Source #
Keeps repeating the computation, until the scheduler expires, or the predicate returns false, or an error occurs
param | schedule | Scheduler strategy for repeating |
param | predicate | Keep repeating while this predicate returns |
returns | The result of the last invocation |
method IO<A> RepeatUntil ( Func<A, bool> predicate) Source #
Keeps repeating the computation until the predicate returns true, or an error occurs
param | predicate | Keep repeating until this predicate returns |
returns | The result of the last invocation |
method IO<A> RepeatUntil ( Schedule schedule, Func<A, bool> predicate) Source #
Keeps repeating the computation, until the scheduler expires, or the predicate returns true, or an error occurs
param | schedule | Scheduler strategy for repeating |
param | predicate | Keep repeating until this predicate returns |
returns | The result of the last invocation |
method IO<A> Retry (Schedule schedule) Source #
Retry if the IO computation fails
This variant will retry until the schedule expires
method IO<A> RetryWhile (Func<Error, bool> predicate) Source #
Retry if the IO computation fails
This variant will keep retrying whilst the predicate returns true
for the error generated at each iteration;
at which point the last raised error will be thrown.
method IO<A> RetryWhile ( Schedule schedule, Func<Error, bool> predicate) Source #
Retry if the IO computation fails
This variant will keep retrying whilst the predicate returns true
for the error generated at each iteration;
or, until the schedule expires; at which point the last raised error will be thrown.
method IO<A> RetryUntil ( Func<Error, bool> predicate) Source #
Retry if the IO computation fails
This variant will keep retrying until the predicate returns true
for the error generated at each iteration;
at which point the last raised error will be thrown.
method IO<A> RetryUntil ( Schedule schedule, Func<Error, bool> predicate) Source #
Retry if the IO computation fails
This variant will keep retrying until the predicate returns true
for the error generated at each iteration;
or, until the schedule expires; at which point the last raised error will be thrown.
class IOExtensions Source #
method IO<A> As <A> (this K<IO, A> ma) Source #
Convert the kind version of the IO
monad to an IO
monad.
This is a simple cast operation which is just a bit more elegant than manually casting.
type | A | |
param | ma | |
returns |
method IO<A> Flatten <A> (this Task<IO<A>> tma) Source #
Get the outer task and wrap it up in a new IO within the IO
method K<M, ForkIO<A>> Fork <M, A> (this K<M, A> ma, Option<TimeSpan> timeout = default) Source #
Queue this IO operation to run on the thread-pool.
param | timeout | Maximum time that the forked IO operation can run for. |
returns | Returns a |
field IO<EnvIO> env = lift(e => e) Source #
field IO<CancellationToken> token = lift(e => e.Token) Source #
field IO<CancellationTokenSource> source = lift(e => e.Source) Source #
field IO<Option<SynchronizationContext>> syncContext = lift(e => Optional(e.SyncContext)) Source #
method IO<A> Fail <A> (Error value) Source #
Put the IO into a failure state
type | A | Bound value type |
param | value | Error value |
returns | IO in a failed state. Always yields an error. |
method IO<A> local <A> (K<IO, A> ma) Source #
Creates a local cancellation environment
A local cancellation environment stops other IO computations, that rely on the same environmental cancellation token, from being taken down by a regional cancellation.
If a IO.cancel
is invoked locally then it will still create an exception that
propagates upwards and so catching cancellations is still important.
type | A | Bound value |
param | ma | Computation to run within the local context |
returns | Result of the computation |
method IO<ForkIO<A>> fork <A> (K<IO, A> ma, Option<TimeSpan> timeout = default) Source #
Queue this IO operation to run on the thread-pool.
param | timeout | Maximum time that the forked IO operation can run for. |
returns | Returns a |
field IO<CancellationToken> cancelToken = IO.lift(e => e.Token) Source #
Access the cancellation-token from the IO environment
returns | CancellationToken |
field IO<Unit> cancel = new (e => { e.Source.Cancel(); throw new TaskCanceledException(); }) Source #
Request a cancellation of the IO expression
field IO<Unit> unitIO = IO<Unit>.Pure(default) Source #
Always yields a Unit
value
field IO<EnvIO> envIO = IO<EnvIO>.Lift(e => e) Source #
Yields the IO environment
method IO<A> local <A> (K<IO, A> ma) Source #
Creates a local cancellation environment
A local cancellation environment stops other IO computations, that rely on the same environmental cancellation token, from being taken down by a regional cancellation.
If a IO.cancel
is invoked locally then it will still create an exception that
propagates upwards and so catching cancellations is still important.
type | A | Bound value |
param | ma | Computation to run within the local context |
returns | Result of the computation |
method K<M, ForkIO<A>> fork <M, A> (K<M, A> ma, Option<TimeSpan> timeout = default) Source #
Queue this IO operation to run on the thread-pool.
param | timeout | Maximum time that the forked IO operation can run for. |
returns | Returns a |
method IO<A> timeout <A> (TimeSpan timeout, K<IO, A> ma) Source #
Timeout operation if it takes too long
method IO<A> repeat <A> (K<IO, A> ma) Source #
Keeps repeating the computation
type | A | Computation bound value type |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> repeat <A> (Schedule schedule, K<IO, A> ma) Source #
Keeps repeating the computation, until the scheduler expires
type | A | Computation bound value type |
param | schedule | Scheduler strategy for repeating |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> repeatWhile <A> (K<IO, A> ma, Func<A, bool> predicate) Source #
Keeps repeating the computation until the predicate returns false
type | A | Computation bound value type |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> repeatWhile <A> ( Schedule schedule, K<IO, A> ma, Func<A, bool> predicate) Source #
Keeps repeating the computation, until the scheduler expires, or the predicate returns false
type | A | Computation bound value type |
param | schedule | Scheduler strategy for repeating |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> repeatUntil <A> ( K<IO, A> ma, Func<A, bool> predicate) Source #
Keeps repeating the computation until the predicate returns true
type | A | Computation bound value type |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> repeatUntil <A> ( Schedule schedule, K<IO, A> ma, Func<A, bool> predicate) Source #
Keeps repeating the computation, until the scheduler expires, or the predicate returns true
type | A | Computation bound value type |
param | schedule | Scheduler strategy for repeating |
param | ma | Computation to repeat |
returns | The result of the last invocation of |
method IO<A> retry <A> (K<IO, A> ma) Source #
Keeps retrying the computation
type | A | Computation bound value type |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |
method IO<A> retry <A> (Schedule schedule, K<IO, A> ma) Source #
Keeps retrying the computation, until the scheduler expires
type | A | Computation bound value type |
param | schedule | Scheduler strategy for retrying |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |
method IO<A> retryWhile <A> ( K<IO, A> ma, Func<Error, bool> predicate) Source #
Keeps retrying the computation until the predicate returns false
type | A | Computation bound value type |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |
method IO<A> retryWhile <A> ( Schedule schedule, K<IO, A> ma, Func<Error, bool> predicate) Source #
Keeps retrying the computation, until the scheduler expires, or the predicate returns false
type | A | Computation bound value type |
param | schedule | Scheduler strategy for retrying |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |
method IO<A> retryUntil <A> ( K<IO, A> ma, Func<Error, bool> predicate) Source #
Keeps retrying the computation until the predicate returns true
type | A | Computation bound value type |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |
method IO<A> retryUntil <A> ( Schedule schedule, K<IO, A> ma, Func<Error, bool> predicate) Source #
Keeps retrying the computation, until the scheduler expires, or the predicate returns true
type | A | Computation bound value type |
param | schedule | Scheduler strategy for retrying |
param | ma | Computation to retry |
returns | The result of the last invocation of ma |